package cn.luke.basic.rs;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回
 */
@Data
public class R implements Serializable {

    private static final Long success_code = 2000L;
    private static final Long error_code = 4000L;

    private Long code;
    private String message;
    private Object data;

    private R() {

    }

    private void setResultMsg(EnumResultMsg result) {
        this.message = result.getValue();
    }

    // 返回成功
    public static R success() {
        R result = new R();
        result.setCode(success_code);
        result.setResultMsg(EnumResultMsg.SUCCESS);
        return result;
    }
    // 返回成功
    public static R success(Object data) {
        R result = new R();
        result.setCode(success_code);
        result.setResultMsg(EnumResultMsg.SUCCESS);
        result.setData(data);
        return result;
    }

    // 返回失败
    public static R fail() {
        R result = new R();
        result.setCode(error_code);
        result.setResultMsg(EnumResultMsg.ERROR);
        return result;
    }
    // 返回失败
    public static R fail_message(String message) {
        R result = new R();
        result.setCode(error_code);
        result.setMessage(message);
        return result;
    }
    // 返回失败
    public static R fail(String message, Object data) {
        R result = new R();
        result.setCode(error_code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    // 返回失败
    public static R fail(Object data) {
        R result = new R();
        result.setCode(error_code);
        result.setResultMsg(EnumResultMsg.ERROR);
        result.setData(data);
        return result;
    }

}
